//
//  MTLuckyEmptyView.swift
//  MT
//
//  Created by ooops on 2020/1/22.
//  Copyright © 2020 张强. All rights reserved.
//

import UIKit
import MTCategory

class MTLuckyEmptyView: UIView {

    override init(frame: CGRect) {
        super.init(frame: frame)
        setupUI()
        makeConstraint()
    }
    
    convenience init(_ title: String? = nil, _ image: String? = nil, _ tapViewBlock: (() -> ())? = nil) {
        self.init(frame: .zero)
        let paraStyle: NSMutableParagraphStyle = NSMutableParagraphStyle()
        paraStyle.alignment = .center
        let attribute = [NSAttributedString.Key.font: PingFangSCRegularFont(14),
                         NSAttributedString.Key.foregroundColor: UIColor(hex: 0x5d5d5d),
                         NSAttributedString.Key.paragraphStyle : paraStyle]
        
        tipLabel.attributedText = NSAttributedString(string: title ?? "这里空空如也...", attributes: attribute)
        
        tipImageView.image = UIImage(named: image ?? "icon_empty")
        
        addGestureRecognizer(UITapGestureRecognizer(actionBlock: { (v) in
            tapViewBlock?()
        }))
    }
    
    lazy var tipLabel: UILabel = {
        let l = UILabel()
        return l
    }()
    
    lazy var tipImageView: UIImageView = {
        let imageV = UIImageView()
        return imageV
    }()
    
    private func setupUI() {
        addSubview(tipImageView)
        addSubview(tipLabel)
    }
    
    private func makeConstraint() {
        tipImageView.snp.makeConstraints { (make) in
            make.centerX.equalToSuperview()
            make.centerY.equalToSuperview().offset(-20)
        }
        
        tipLabel.snp.makeConstraints { (make) in
            make.centerX.equalToSuperview()
            make.top.equalTo(tipImageView.snp.bottom)
        }
    }
    
    required init?(coder: NSCoder) {
        super.init(coder: coder)
    }


}
